import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, NavigationExtras, Router, Params } from '@angular/router';
import { Location } from '@angular/common';
// 服务
import { LoadingAnimateService } from '../../../common/loading';
import { EventService } from './event.service';

import { EventList, EventResult, EventHookResult } from './event';
import { AlertService } from '../../../common/alert';
@Component({
    moduleId: module.id,
    templateUrl: 'event-hook.component.html',
    providers: [EventService]
})
export class EventHookComponent implements OnInit {

    eid: string;
    isNull: boolean;
    datas: EventHookResult[];
    evt: EventResult;
    constructor(
        private router: Router,
        private route: ActivatedRoute,
        private loadingService: LoadingAnimateService,
        private eventService: EventService,
        private alert: AlertService,
        private location: Location
    ) { }

    ngOnInit(): void {
        this.route.params.subscribe((params: Params) => {
            this.eid = params['id'] || '';
            this.evt = this.eventService.tmp();
            if (this.eid == this.evt.eid) {
                this.find()
            } else {
                this.alert.showBlock("查询参数错误").subscribe(v => this.location.back())
            }
        });
    }

    find(): void {
        this.loadingService.setValue(true);
        this.eventService.hookinfo(this.eid).then(
            res => {
                this.loadingService.setValue(false);
                if (res == null || res.length == 0) {
                    this.isNull = true;
                } else {
                    this.isNull = false;
                }
                this.datas = res
            }
        );
    }

}
